package com.nf.xiaomi.web.controller;

import com.nf.mvc.ViewResult;
import com.nf.mvc.mapping.RequestMapping;
import com.nf.mvc.support.ResponseVO;
import com.nf.xiaomi.entity.AddressEntity;
import com.nf.xiaomi.service.AddressService;
import com.nf.xiaomi.service.impl.AddressServiceImpl;
import com.nf.xiaomi.util.JsonUtils;

import java.util.List;

import static com.nf.mvc.handler.HandlerHelper.json;

@RequestMapping("/address")
public class AddressController {
    AddressService service = new AddressServiceImpl();

    @RequestMapping("/getAll")
    public ViewResult getAll() {
        List<AddressEntity> list = service.getAll();
        return json(new ResponseVO(200, "ok", list));
    }

    @RequestMapping("/getAllUserID")
    public ViewResult getAllUserID(Long account) {
        List<AddressEntity> list = service.getAll(account);
        return json(new ResponseVO(200, "ok", list));
    }

    @RequestMapping("/getAllAddressID")
    public ViewResult getAllAddressID(Integer addressId) {
        List<AddressEntity> list = service.getAll(addressId);
        return json(new ResponseVO(200, "ok", list));
    }

    @RequestMapping("/insert")
    public ViewResult insert(AddressEntity addressEntity) {
        int insert = service.insert(addressEntity);
        return JsonUtils.Result(insert);
    }

    @RequestMapping("/update")
    public ViewResult update(AddressEntity addressEntity) {
        int update = service.update(addressEntity);
        return JsonUtils.Result(update);
    }

    @RequestMapping("/delete")
    public ViewResult delete(Integer addressId) {
        int delete = service.delete(addressId);
        return JsonUtils.Result(delete);
    }
}

